package com.bolt.report.business.test;

import com.bolt.support.codegenerator.dto.ConfigInfo;
import com.bolt.support.codegenerator.model.Table;
import com.bolt.support.codegenerator.util.GeneratorUtil;
import freemarker.template.Configuration;
import freemarker.template.TemplateException;

import java.util.Collections;

public class CodeHelper {

    ///////////////////////////////////////////////////mySql//////////////////////////////////////////////////////////////////
    private static String JDBC_URL = "jdbc:mysql://127.0.0.1:3306/bolt_db?useUnicode=true&characterEncoding=utf-8&useSSL=false";
    private static String JDBC_USER = "root";
    private static String JDBC_PASSWORD = "123456";
    private static String JDBC_DRIVER = "com.mysql.jdbc.Driver";

    /////////////////////////////////////////////////////Oracle//////////////////////////////////////////////////////////////////
//    private static String JDBC_URL = "jdbc:oracle:thin:@82.157.37.170:1521:HDDB";
//    private static String JDBC_USER = "HDMRD";
//    private static String JDBC_PASSWORD = "HDMRD";
//    private static String JDBC_DRIVER = "oracle.jdbc.OracleDriver";


    //    private static String path = "E:\\HDYY.CDR\\2.CodeSource\\CDR-server\\cdr-business-center\\cdr-business-common\\src\\main\\java";
//    private static String path = "E:\\EmrBaoDian\\CDR-server\\cdr-business-center\\cdr-business-medicalknowledge\\src\\main\\java";
//    private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-common\\src\\main\\java";
//    private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-empi\\src\\main\\java";
//    private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-masterdata\\src\\main\\java";
//    private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-masterdata-api\\src\\main\\java";
//    private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-emr\\src\\main\\java";
//      private static String path = "D:\\myworkspace\\cdr-parent\\cdr-auth\\auth-biz\\src\\main\\java";
//   private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-book\\src\\main\\java";
//   private static String path = "D:\\hd\\cdr\\cdr-parent\\cdr-business-center\\cdr-business-book-api\\src\\main\\java";
   // private static String path = "D:\\myworkspace\\cdr-parent\\cdr-business-center\\cdr-business-book-api\\src\\main\\java";
    private static String path = "C:\\Users\\Administrator\\Desktop\\logs\\java";


    private CodeGeneratorService sourceCodeBuilder;

    public CodeHelper() {
        sourceCodeBuilder = new CodeGeneratorService(JDBC_URL, JDBC_USER, JDBC_PASSWORD, JDBC_DRIVER);
    }

    private Configuration getConfiguration() throws TemplateException {
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
        // 设置FreeMarker的模版文件位置
        cfg.setClassForTemplateLoading(CodeHelper.class, "/code-template");
        cfg.setNumberFormat("###############");
        cfg.setBooleanFormat("true,false");
        cfg.setDefaultEncoding("UTF-8");
        return cfg;
    }

    public void codeGenerator(String basePackage, String tableName) {
        try {
            Table table = sourceCodeBuilder.getTable(tableName);
            ConfigInfo configInfo = new ConfigInfo();
            configInfo.setPack(basePackage);
            configInfo.setTableName(tableName);
            configInfo.setColumnInfos(Collections.emptyList());
            configInfo.setPath(path);
            configInfo.setFullTableName(false);
            sourceCodeBuilder.getTable(tableName);
            GeneratorUtil.generatorCode("Controller", table, getConfiguration(), configInfo);
            GeneratorUtil.generatorCode("Service", table, getConfiguration(), configInfo);
            GeneratorUtil.generatorCode("Repository", table, getConfiguration(), configInfo);
            GeneratorUtil.generatorCode("Converter", table, getConfiguration(), configInfo);
            GeneratorUtil.generatorCode("Entity", table, getConfiguration(), configInfo);
            GeneratorUtil.generatorCode("Dto", table, getConfiguration(), configInfo);
            GeneratorUtil.generatorCode("QueryCriteria", table, getConfiguration(), configInfo);

        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public static void main(String[] args) {
        CodeHelper helper = new CodeHelper();
//        helper.codeGenerator("com.hdyy.business.knowledge", "COMMON_PHARMACY");
//        helper.codeGenerator("com.bolt.auth.security.admin.biz.sys", "oauth_client_details");

        ccm(helper);
    }

    private static void ccm(CodeHelper helper) {
        helper.codeGenerator("com.bolt.report.business.modules.link", "bolt_report_link");

//        helper.codeGenerator("com.hdyy.business.datamapping", "BUSINESS_BUILDING");
//        helper.codeGenerator("com.hdyy.business.datamapping", "COMMON_ORGANIZATION");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_BED_TYPE");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_TRIAGE2DEPT");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_ORG");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_ORG2SYS_ORG");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_BUILDING");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_DEPARTMENT");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_DEPARTMENT2SYS_DEPT");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_EMPLOYEE");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_EMPLOYEE2SYS_USER");
//        helper.codeGenerator("com.hdyy.business.book.module.system", "BOOK_PARAM");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_RESOURCE_POOL");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_SCHEDULE_DOCTOR");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_SCHEDULE_EXCEPTION");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_TIMELINE_SET");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_TYPE_INFO");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_RESOURCE_POOL");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_SCHEDULE_DOCTOR");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_SCHEDULE_EXCEPTION");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_TIMELINE_SET");
//        helper.codeGenerator("com.hdyy.business.book.module.rule", "BOOK_TYPE_INFO");
//        helper.codeGenerator("com.hdyy.business.empi", "EMPI_DICT_DATA");
//        helper.codeGenerator("com.hdyy.business.empi", "EMPI_LOG");
//        helper.codeGenerator("com.hdyy.business.empi", "EMPI_DATA_RULE");
//        helper.codeGenerator("com.hdyy.business.empi", "EMPI_IDENTIFIER");
//        helper.codeGenerator("com.hdyy.business.empi", "EMPI_MATCH_RULE");
//        helper.codeGenerator("com.hdyy.business.empi", "EMPI_PERSON_BASE_INFO");
        //    helper.codeGenerator("com.hdyy.business.main.module.mq", "oauth_client_details");
//        helper.codeGenerator("com.hdyy.business.masterdata", "SYS_DICT_DATA");
//        helper.codeGenerator("com.hdyy.business.masterdata", "COMMON_TERMS_DICTIONARY");

//        helper.codeGenerator("com.hdyy.business.emr", "CDA_DOCUMENT_EMR");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ADMISSION_ASSESSMENT");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ADMISSION_DEATH_IN24H");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ADMISSION_DISCHARGE_IN24H");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ADMISSION_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ADMISSION_RECORD_COM");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ADMISSION_RECORD_DIAG");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ANESTHESIA_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_AWAITING_DELIVERY");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_BLOOD_TRANSFUSION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CARE_PLAN");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CESAREAN_SECTION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CONSENT_ANESTHESIAINFORMED");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CONSENT_OPERATION_INFORMED");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CONSENT_OTHER_INFORMED");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CONSENT_SPECIAL_EXAM");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CONSENT_TRANSFUSIONTHERAPY");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CONSULTATION_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_CRITICAL_CONDITION_NOTICE");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_DAILY_COURSE");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_DEATH_CASES_DISCUSSION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_DEATH_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_DISCHARGED_BRIEF");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_DISCHARGE_ASSESSMENT");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_DISCHARGE_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_EMERGENCY_OBSERVATION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_EXAMINATION_REPORT");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_EXPENSIVECONSUMABLES_USAGE");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_FIRST_COURSE");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_GENERAL_NURSING");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_GENERAL_SURGERY_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_INPATIENT_ORDER");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_INTAKE_AND_OUTPUT_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_INTRACTABLECASE_DISCUSSION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_LABORATORY_TEST_REPORT");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_MR_FIRSTPAGE_CHARGE_CODE");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_MR_FIRSTPAGE_TCM");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_MR_FIRSTPAGE_WM");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_MR_FIRSTPAGE_WM_DIAG");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_MR_FIRSTPAGE_WM_OPERATION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_ORGANIZATION_INFO");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_OUTPATIENT_EMERGENCY");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_POSTOPERATION_ANESTHESIA");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_POSTOPERATIVE_FIRST_TIME");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_PREOPERATIVE_ANESTHESIA");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_PREOPERATIVE_DISCUSSION");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_PREOPERATIVE_SUMMARY");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_PRESCRIPTION_TCM");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_PRESCRIPTION_WM");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_REFERRAL_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_RELIEF_SHIFT_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_RESCUE_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SERIOUS_CRITICAL_NURSING");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_STAGE_SUMMARY");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SUMMARY_BASIC_HEALTH_INFO");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SUMMARY_HEALTH_EVENTS");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SUMMARY_MEDICAL_COSTS");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SUMMARY_PATIENT_BASE_INFO");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SUPERIOR_DOCTORS_WARD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_SURGICAL_NURSING");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_THERAPY_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_TRANSFERRED_RECORD");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_VAGINAL_DELIVERY");
//        helper.codeGenerator("com.hdyy.business.emr", "EMR_VITAL_SIGNS_MEASUREMENT");
    }


}